package cn.edu.bupt.ch10_1.msorder.controller;

import cn.edu.bupt.ch10_1.msorder.facade.InventroyFacade;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order/feign")
public class FeignDemoController {
    @Autowired
    private InventroyFacade inventroyFacade;

    @SentinelResource(value = "order", blockHandler = "blockHandlerOrder")
    @GetMapping("/{product_uuid}/{num}")
    public String order(@PathVariable("product_uuid") String product_uuid,
                              @PathVariable("num") String num){

        return inventroyFacade.deduct(product_uuid,num) ;
    }

    public String blockHandlerOrder(String product_uuid, String num, BlockException e){

        return  "被限流了" ;
    }
}